//
// Created by zhupi on 2024/9/6.
//

#ifndef DEMO2_MAIN_WINDOW_FILE_H
#define DEMO2_MAIN_WINDOW_FILE_H

#include <QMenuBar>
#include <QProxyStyle>
#include <QStyleOptionMenuItem>

// 自定义样式以覆盖菜单项的宽度
class FixedWidthStyle : public QProxyStyle {
public:
    FixedWidthStyle(int width) : menuWidth(width) {}

    QSize sizeFromContents(ContentsType type, const QStyleOption *option,
                           const QSize &size, const QWidget *widget) const override {
        QSize s = QProxyStyle::sizeFromContents(type, option, size, widget);
        if (type == QStyle::CT_MenuItem) {
            s.setWidth(menuWidth); // 设置固定宽度
        }
        return s;
    }

private:
    int menuWidth;
};

class MainWindowMenuBar : public QMenuBar
{
    Q_OBJECT
public:
    explicit MainWindowMenuBar(QWidget *parent);
    void Initial();

private:
};


#endif //DEMO2_MAIN_WINDOW_FILE_H
